package com.cas.webservice.model;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;

import com.cas.object.Download_trace_Commond;
import com.cas.scalls.util.HttpUtil;
import com.cas.scalls.util.ObjectData;
import com.cas.scalls.util.SqliteUtil;
import com.cas.scalls.util.TCPClient;

public class DownloadInInfo extends TimerTask {

	public void downloadInInfo() throws Exception {
			makecmdForPC("127.0.0.1");
	}

	@Override
	public void run() {
		try {
			new DownloadInInfo().downloadInInfo();
		} catch (Exception e) {

		}
	}

	public static List<byte[]> makecmdForPC(String url) throws Exception {
		try {
			List<ObjectData> objlist = new ArrayList<ObjectData>();
			
			
			if (HttpUtil.doPost(url, null, "connectable").equals("1")) {
				ResultSet rs = SqliteUtil.select("select ip from proprietor;");
				while (rs.next()) {
					ObjectData obj = new  ObjectData(rs.getString("ip"));
					obj.strtopc = Download_trace_Commond.makeDownloadTraceCommondForPc(rs.getString("ip"));
					objlist.add(obj);
					//rSendBufList.addAll(Download_trace_Commond.makeTraceBytesFromString(), rs.getString("ip")));
				}
			}
			for(ObjectData obj:objlist){
				obj.strfrompc = HttpUtil.doPost(url, obj.strtopc, "downloadInInfo");
			}
			for(ObjectData obj:objlist){
				obj.listbyte = Download_trace_Commond.makeTraceBytesFromString(obj.strfrompc, obj.ipaddr);
			}
			for(ObjectData obj:objlist){
				ThreadControl th = new ThreadControl(obj.ipaddr,20304,obj.listbyte);
				th.start();
			}
			
		} catch (Exception e) {
		}
		return null;
	}

}
